import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { failHandler, getPkgInfo } from "@/common";
import { getCommand } from "@/base";

const { version } = getPkgInfo();

export const createCli = () => {
  const argv = hideBin(process.argv);
  const cli = yargs(argv);

  return cli
    .strict()
    .version(version)
    .alias("h", "help")
    .alias("v", "version")
    .demandCommand(1)
    .command(
      getCommand({
        command: "npm",
        describe: "发布npm包",
      }),
    )
    .command(
      getCommand({
        command: "web",
        describe: "发布web包",
      }),
    )
    .usage("Usage: $0 <command> [options]")
    .help("help")
    .fail(failHandler).argv;
};
